
def bubble(l):
    print( 'before sort', l )
    for index in range(len(l) - 1, 0 , -1):
        for two_index in range(index):
            if l[two_index] > l[two_index + 1]:
                l[two_index], l[two_index + 1] = l[two_index + 1], l[two_index]
    print( 'after sort', l )

listsort = [10, 20, 40, 50, 30, 60]
bubble(listsort)

'''
就是依次遍历，把最小的数字沉到数组的最后
'''
listsort = [10, 20, 40, 50, 30, 60]
def bubblelmx( inarr ):
    print( ' bubblelmx before sort', inarr )
    for index in range(  len(inarr)-1):
        for indexTwo in range( len(inarr)-1-index  ):
            if inarr[indexTwo]<inarr[indexTwo+1]:
                inarr[indexTwo], inarr[indexTwo+1] =  inarr[indexTwo+1], inarr[indexTwo]
    print( ' bubblelmx after sort', inarr )

bubblelmx(listsort)

'''
  鸡尾酒排序， 也就是冒泡排序的一种变种， 算法复杂度 , 最糟或平均 O[n2], n2 为n的平方， 最好为 O[n], 在多数数据已排序情况下
  // 整除
'''
listsort = [10, 20, 40, 50, 30, 60, 51]

'''
# 第二个循环之所以是减2 ， 原因是第一次循环时， 已经将最大值排列出来了
def cocktailSortlmx( arrin):
    print( ' cocktailSortlmx before sort', inarr )
    size = len( arrin)
    sign = 1
    for index in range( size // 2 ):
        if sign:
            sign = 0
            for
        else:
            break
    print( ' cocktailSortlmx after sort', inarr )
'''

def cocktail_sort(l):
    print( ' cocktail_sort before sort', l )
    size = len(l)
    sign = 1  
    for i in range(size // 2 ):
        if sign:
            sign = 0
            for j in range(i, size - 1 - i):
                if l[j] > l[j + 1]:
                    l[j], l[j + 1] = l[j + 1], l[j]
            print( ' cocktail_sort max sort', l )
            for k in range(size - 2 - i, i, -1):
                if l[k] < l[k - 1]:
                    l[k], l[k - 1] = l[k - 1], l[k]
                    sign = 1  
            print( ' cocktail_sort min sort', l )
        else:
            break
    print( ' cocktail_sort after sort', l )


cocktail_sort(listsort)